<template>
  <div class="">
    <div class="yuwenmain">
      <div v-if="list.length > 0">
        <div class="item" v-for="(item, index) in list" :key="index">
          <div class="item-left">
            <div class="name">{{ item.doctorName }}</div>
            <div class="keshi">{{ item.departmentName }}</div>
            <div class="hos">{{ item.hospitalName }}</div>
            <div class="pep">
              <span>就诊人</span> {{ item.name }} {{ item.treatDate }}
              {{ item.week }}{{ item.sourceTypeName }}
            </div>
          </div>
          <div class="item-right" @click="goyuwenzhen(item)">预问诊</div>
        </div>
      </div>
      <div class="" v-else>
        <van-empty description="您有预约订单后,才可以使用预问诊功能" />
      </div>
    </div>
  </div>
</template>
<script>
import { Dialog, Toast } from "vant";
import { Empty } from "vant";
import { Tab, Tabs, Popup } from "vant";
import { orderRecordApi, shangbaoApi } from "@/service/api.js";
import { loginByWxOpenidApi } from "@/service/api.js";
export default {
  name: "index",
  inject: ["reload"],
  data() {
    return {
      apptoken: "",
      token: "",
      list: []
    };
  },
  created() {
    localStorage.getItem("apptoken"),
      (this.apptoken = JSON.parse(localStorage.getItem("apptoken"))),
      console.log(this.apptoken);
    // 拿取token
    this.token = localStorage.getItem("token");
    this.getorderList();
  },
  methods: {
    goyuwenzhen(val) {
      console.log(val.registerId);
      let token = localStorage.getItem("token");
      let apptoken = JSON.parse(localStorage.getItem("apptoken"));
      shangbaoApi({
        apptoken: apptoken,
        token: token,
        department: val.departmentName,
        scene: "0101015",
        qrCodeText: val.qrCodeText
      }).then(res => {
        console.log(res);
        if (res.code == 4000) {
          console.log(res);
        } else if (res.code == 4002) {
          window.localStorage.removeItem("token");
          Dialog.confirm({
            title: "提示",
            message: "需前往登录页面完成登录"
          })
            .then(() => {
              this.$router.push({
                name: "login"
              });
              // on confirm
            })
            .catch(() => {
              // on cancel
            });
        }
      });
      var registerId = val.registerId;
      var url = `https://miying.qq.com/guide-h5-prediagnosis/pages/prediagnosis?partnerId=100000197&hospitalId=20000806&registerId=${registerId}`;
      window.location.href = `https://miying.qq.com/guide-h5-prediagnosis/pages/prediagnosis?partnerId=100000197&hospitalId=20000806&registerId=${registerId}`;
      // Toast("点击弹出"+url)
    },
    getorderList() {
      orderRecordApi({
        token: this.token,
        apptoken: this.apptoken
      }).then(res => {
        if (res.code == 4000) {
          console.log(res);
          this.list = res.data.waitTreatOrders;
          console.log(this.list.lenght);
        } else {
          if (res.code == 4002) {
            window.localStorage.removeItem("token");
            Dialog.confirm({
              title: "提示",
              message: "需前往登录页面完成登录"
            })
              .then(() => {
                this.$router.push({
                  name: "login"
                });
                // on confirm
              })
              .catch(() => {
                // on cancel
              });
          } else {
            Toast(res.msg);
          }
        }
      });
    }
  }
};
</script>
<style lang="scss">
.yuwenmain {
  width: 100%;
  background-color: #f6f6f6;
  padding-bottom: 100vh;
  overflow: hidden;
  margin-top: 1rem;
  .item {
    width: 100%;
    margin: 0 auto;
    padding-top: 0.3rem;
    margin-top: 0.2rem;
    padding-bottom: 0.2rem;
    background-color: #fff;
    display: flex;
    justify-content: space-between;
    .item-left {
      font-size: 0.35rem;
      width: 80%;
      margin-left: 0.2rem;
      .name {
        font-size: 0.4rem;
        font-weight: bold;
        padding-bottom: 0.1rem;
      }
      .keshi {
        padding-bottom: 0.1rem;
      }
      .hos {
        padding-bottom: 0.1rem;
      }
      .pep {
        span {
          color: #888;
        }
      }
    }
    .item-right {
      width: 15%;
      margin-top: 0.3rem;
      text-align: center;
      line-height: 1rem;
      margin-right: 10px;
      height: 1rem;
      color: #fff;
      font-size: 0.4rem;
      background-color: #07c6b4;
      border-radius: 10px;
    }
  }
}
</style>
